<?php

class User_Controller_Admincp_Manage_Resetpwd extends Nuo_Controller_Admincp
{
	function execute($request)
	{
		$id = $request -> getParam('user_id');
		
		$table = Nuo::getTable('user');
		
		$form = Nuo::getObject('user/admincp/manage/resetpwd', 'form');
		
		$item = NULL;

		if ($id)
		{
			$item = $table -> find($id) -> current();
		}

		if ($request -> isGet() && $item)
		{
			$form -> setData($item -> toArray());
		}

		if ($request -> isPost() && $form -> isValid($_POST))
		{
			$data = $form -> getData();

			$item -> setPassword($data['password']);

			$item -> save();

			Nuo_Messenger::instance()->add(Intl::__('Password changed!'));
			
			return  'nuo.refresh();';
			return;
		}

		return  Nuo::getView()->render('core/view/controller/admincp/edit', array('form' => $form));
	}

}
